
function CreateRequest(func) {
    var xmlhttp;
    if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
    }
    else {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=func;
    return xmlhttp;
}

function UpdateCategoryInternal(id, name) {
    var request = CreateRequest(function() {
        
    });
    request.open("GET","UpdateCategory.php?id="+id+"&name="+name,true);
    request.send();
}

function UpdateCategory(id, elementID) {
    var val = document.getElementById(elementID).value;
    UpdateCategoryInternal(id, val);
}

function UpdateQuestionInternal(id, question) {
    var request = CreateRequest(function() {
        
    });
    request.open("GET","UpdateQuestion.php?id="+id+"&question="+question,true);
    request.send();
}

function UpdateAnswerInternal(id, answer) {
    var request = CreateRequest(function() {
        
    });
    request.open("GET","UpdateAnswer.php?id="+id+"&answer="+answer,true);
    request.send();
}

function UpdateQuestion(id, elementID) {
     var val = document.getElementById(elementID).value;
    UpdateQuestionInternal(id, val);
}

function UpdateAnswer(id, elementID) {
    var val = document.getElementById(elementID).value;
    UpdateAnswerInternal(id, val);
}

function DeleteQuestion(id) {
    if (confirm("Vil du virkelig slette spørgsmålet?")) {
        var request = CreateRequest(function() {
             window.location.reload();
        });
        request.open("GET","DeleteQuestion.php?id="+id,true);
        request.send();
    }
}

function CreateQuestion(categoryID) {
    var request = CreateRequest(function() {
         window.location.reload();
    });
    request.open("GET","CreateQuestion.php?categoryID="+categoryID,true);
    request.send();
}

function CreateCategory(ownerID) {
    var request = CreateRequest(function() {
        window.location.reload();
    });
    request.open("GET","CreateCategory.php?ownerID="+ownerID,true);
    request.send();
}

function DeleteCategory(id) {
    if (confirm("Vil du virkelig slette kategorien og alle dens spørgsmål?")) {
        var request = CreateRequest(function() {
            window.location.reload();
        });
        request.open("GET","DeleteCategory.php?id="+id,true);
        request.send();
    }
}



